/**
 * Copyright (C), 2015-2021, XXX有限公司
 * FileName: RoadGrowthActivity
 * Author: Gxjkz
 * Date: 2021/7/23 11:19
 * Description: 成长之路
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
package com.niuxiaofa.newlaw.Activity;

import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.viewpager.widget.ViewPager;

import com.niuxiaofa.newlaw.Base.BaseActivity;
import com.niuxiaofa.newlaw.Bean.MonitorInfoBean;
import com.niuxiaofa.newlaw.Network.ApiService;
import com.niuxiaofa.newlaw.Network.ServiceManager;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.IndicatorViewTool;
import com.niuxiaofa.newlaw.Tools.UIUtils;
import com.niuxiaofa.newlaw.adapter.RoadGrowthHolderCreator;
import com.to.aboomy.banner.Banner;
import com.to.aboomy.banner.ScaleInTransformer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @ClassName: RoadGrowthActivity
 * @Description: java类作用描述
 * @Author: Gxjkz
 * @Date: 2021/7/23 11:19
 */
public class RoadGrowthActivity extends BaseActivity {


    @BindView(R.id.banner)
    Banner banner;
    List<Map> listEntityList = new ArrayList<>();


    @BindView(R.id.start)
    TextView start;


    @BindView(R.id.rwqk_linear)
    LinearLayout rwqk_linear;


    @BindView(R.id.sjjx)
    LinearLayout sjjx;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_roadgrowth;
    }

    MonitorInfoBean baseBean;

    @Override
    protected void initData() {

        setTitle("成长之路");

        for (int i = 0; i < 5; i++) {
            Map map = new HashMap();
            map.put("monitorStar", "123");
            map.put("number", 1);
            map.put("received",false);

            listEntityList.add(map);
        }
        setBanner();
        Call<MonitorInfoBean> call = ServiceManager.getInstance().creat(ApiService.class).getMonitorInfo();

        call.enqueue(new Callback<MonitorInfoBean>() {
            @Override
            public void onResponse(Call<MonitorInfoBean> call, Response<MonitorInfoBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    baseBean = (MonitorInfoBean) response.body();
                    if (baseBean.getData() == null) {
                        return;
                    }

                        for (int i = 0; i < 3; i++) {
                            Map map = new HashMap();
                            map.put("monitorStar", baseBean.getData().getMonitorStar());
                            map.put("number", baseBean.getData().getNumber());
                            map.put("received", baseBean.getData().isReceived());
                            listEntityList.add(map);
                        }
                }
            }

            @Override
            public void onFailure(Call<MonitorInfoBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(), "网络连接异常,请稍候在试", Toast.LENGTH_LONG).show();
            }
        });


    }



    public void setBanner(){

        banner.setAutoPlay(false);
        banner.setIndicator(IndicatorViewTool.getIndicatorView()).setHolderCreator(new RoadGrowthHolderCreator()).setPages(listEntityList);
        banner.setPageMargin(UIUtils.dp2px(UIUtils.getContext(), 20), UIUtils.dp2px(UIUtils.getContext(), 10))
                .setPageTransformer(true, new ScaleInTransformer());


        banner.setOuterPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                Log.e("111---1", position + "");

                setStartValue(position);
            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });





    }

    public  void  setStartValue(int c){

        switch (c){

            case 0:
                start.setText("升级一星之路");

                rwqk_linear.setVisibility(View.GONE);
                sjjx.setVisibility(View.VISIBLE);
                break;

            case 1:
                start.setText("升级二星之路");
                sjjx.setVisibility(View.VISIBLE);
                rwqk_linear.setVisibility(View.VISIBLE);
                break;

            case 2:
                start.setText("升级三星之路");
                rwqk_linear.setVisibility(View.VISIBLE);
                break;

            case 3:
                start.setText("升级四星之路");
                rwqk_linear.setVisibility(View.VISIBLE);
                break;

            case 4:
                rwqk_linear.setVisibility(View.VISIBLE);
                start.setText("升级五星之路");
                sjjx.setVisibility(View.VISIBLE);
                break;

            case 5:
                rwqk_linear.setVisibility(View.VISIBLE);
                start.setText("任务情况");
                sjjx.setVisibility(View.GONE);
                break;

        }


    }
}